home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / hershey.c < prev    next >
Text File  |  1985-06-03  |  4KB  |  116 lines

  1. #include <stdio.h>
  2. #define TRUE  1
  3. #define FALSE 0
  4. #define XLIM 600    /* Right hand edge of screen */
  5. #define YLIM 200    /* Bottom of the screen */
  6. #define XSC 2          /* X scale factor */ 
  7. #define YSC 1         /* Y scale - to adjust for aspect ratio */ 
  8. #define YSTEP 30    /* Number of dots between lines of characters */        
  9. FILE *fp;    
  10. struct point
  11. {
  12.     int x;
  13.     int y;
  14. };
  15. struct point home;
  16. main()
  17. {
  18. FILE *fopen();
  19. int seqno,penup,xloc,ypos,lbound,rbound,xpos,yloc,xp,yp,np;
  20. int rax,rbx,rcx,rdx;
  21. np=0;            /* We've plotted no points yet */
  22. penup=TRUE;        /* Start with pen off of paper */
  23. xloc=10;        /* Starting position at upper left */
  24. ypos=25;
  25. fp=fopen("hershey.dat","r");
  26. if (fp==NULL)        /* Couldn't find the data base? */
  27. {
  28.     printf("Diskette with HERSHEY.DAT must be in default  drive.");
  29.     exit(1);
  30. }          
  31. initp();            /* Initialize graphics */ 
  32. while(fscanf(fp,"%d",&seqno)!=EOF)    /* Read and skip sequence number */
  33. {
  34.     getcolon();    /* Gobble up the colon between coordinate pairs */
  35.     np=0;        /* Initialize point count for this character */
  36.     fscanf(fp,"%d%d",&lbound,&rbound); /* Get Left and Right limits */
  37.     getcolon();    /* Eat that colon */
  38.     np++;        /* Count number of points */
  39.     lbound*=XSC;    /* Scale Left limit to screen size */
  40.     rbound*=XSC;    /* Ditto for Right limit */
  41.     xpos=xloc+(rbound-lbound)/2;    /* Calculate center of character */
  42.       movit(xpos,ypos);    /* Move to center of character */
  43.     penup=TRUE;    /* Make sure pen is up */
  44.     while(TRUE)     
  45.     {
  46.         if(np>14)    /* Only 15 points on a data image */
  47.         {
  48.             np=0;    /* Reset point counter */
  49.             getcolon();    /* Eat colon to get to coordinate */         
  50.         }
  51.         fscanf(fp,"%d%d",&xp,&yp);    /* Read an X,Y pair */
  52.         getcolon();
  53.         np++;
  54.         if(xp==-64 && yp==-64)    /* X=-64, Y=-64 is end of character */
  55.             break;    /* So, exit from loop */
  56.         if(xp!=-64)    /* X=-64 would mean new line segment */
  57.         {
  58.             xp*=XSC;     /* Scale coordinates */
  59.             yp*=YSC;
  60.             xp+=xpos;    /* Update new X,Y positions */
  61.             yp+=ypos;
  62.             if(penup)    /* If pen is UP */
  63.             {
  64.                  movit(xp,yp); /* Move to this point */  
  65.                 penup=FALSE;    /* And put pen down */
  66.             }
  67.             else                  /* Pen is alread down, so */      
  68.                 drawit(xp,yp);  /* Draw to new point */  
  69.         }
  70.         else            /* This is a new line segment */
  71.             penup=TRUE;    /* So, lift the pen */
  72.     }
  73.     xloc+=(rbound-lbound);        /* Compute new X location */
  74.     if(xloc>=XLIM)            /* Run off right edge of screen ? */
  75.     {
  76.         xloc=10;        /* Yes, move back to left edge */
  77.         ypos+=YSTEP;        /* And move down one line */
  78.         if(ypos>=YLIM)        /* Did we fall off the bottom? */
  79.         {
  80.             scanf("%d",ypos);
  81.             ypos=25;    /* Yes, move back to top of screen */
  82.             initp();        /* And clear the screen */
  83.         }
  84.     }
  85. }
  86. }
  87. initp()            /* Initialize Graphics and clear screen */    
  88. {
  89.       grinit(2,0,0);   /* Hi-res, dummy, dummy  */
  90. }
  91.  
  92. movit(ax,ay)        /* Move to AX, AY */
  93. int ax,ay;
  94. {
  95.     home.x=ax;    /* Just reset home coordinate */
  96.     home.y=ay;
  97.     return;
  98. }
  99. drawit(ax,ay)        /* Draw a line between HOME and AX,AY */
  100. int ax,ay;
  101. {
  102.     struct point pos;
  103.     pos.x=ax;
  104.     pos.y=ay;
  105.       grline(&home,&pos,1);  /* MOVE to HOME position, DRAW to POS */ 
  106.     home.x=pos.x;           /* Update HOME position */    
  107.     home.y=pos.y;
  108.     return;
  109. }
  110. getcolon()    /* Gobble up colons in database */
  111. {
  112.     while(getc(fp)!=':')  /* Read everything up to and including */ 
  113.     {              /* The next colon */    
  114.     }    
  115. }
  116.